﻿// DateSelector shows a date selector dialog when clicked
define([
    'Wjs/ui/widgets/tools/Tool',
    'Wjs/ui/widgets/foundation/Overlay',
    'Wjs/ui/widgets/foundation/ViewHashContainer',
    'Wjs/ui/widgets/DatePicker',
    'Wjs/ui/widgets/TimePicker'
],
function () {
    'use strict';

    return Wjs.defineOnce({

        type: 'DateTimeSelector',

        internal: {

            base: Wjs.getType('Tool'),

            onBeforeTypeDefined: function () {

                Wjs.define({

                    type: 'DateTimePicker',

                    internal: {

                        base: 'ViewHashContainer',

                        initialize: function () {

                            this.addSection('datePicker',

                                Wjs.new('DatePicker')
                            );

                            this.addSection('timePicker',

                                Wjs.new('TimePicker')
                            );
                        }
                    },

                    getDatePicker: function () {

                        return this.getSection('datePicker');
                    },

                    getTimePicker: function () {

                        return this.getSection('timePicker');
                    }
                });
            },

            initialize: function () {
                var me = this;

                me.addClass('wjs-date-time-selector');

                me.dateTimePicker = Wjs.new('Overlay')
                                    .setItem(

                                        Wjs.new('DateTimePicker')
                                    );

                me.onRender(function () {

                    me.dateTimePicker.render();
                });

            }
        },

        clickHandler: function () {

            this.datePicker.show();
        }
    });
});